 <%   
 /** 
 * Description : defect list detail view with defectID
 *** supposed to recever defectID from previous page***
 * update : none
 * Date : 2/28/2014, update date :
 * Written by : Team B(Kapsoo kim(nagoorum@naver.com) )
 */ 
 %>
 
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %> 
<%@ page import="java.util.ArrayList" %>
<%@ page import="com.DefectTracking.*" %>
<!------------------------------------------------->
<!-------------------head ----------------------->
<!------------------------------------------------->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Defect Tracking System</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.4.2/pure-min.css">
</head>
<body>
            
<center>
<br>
<div class="pure-g">
	<style scoped>
        .button-secondary {
            color: white;
            border-radius: 4px;
            text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
        }
        .button-secondary {
            background: rgb(66, 184, 221); /* this is a light blue */
        }

	</style>
	
    <div class="pure-u-1-3"> </div>
    <div class="pure-u-1-3">
    	<button class="button-secondary pure-button">Defect Tracking System</button> 
    </div>
    <div class="pure-u-1-3"> Team B </div>
</div>
<br><br>
<!------------------------------------------------->
<!-------------------head ----------------------->
<!------------------------------------------------->

<u><h3>Detail of the defect</h3></u>

<!------------------------------------------------->
<!-------------------edit defect and update ----------------------->
<!------------------------------------------------->

<form class="pure-form pure-form-aligned" action="./edit_update_proc.jsp" method="POST">
	
<%
		//retrieve "defectid" value from list_detail.jsp file
		int defect_id = Integer.parseInt(request.getParameter("defectid"));
	
		//Declear DefectDetail 
		DefectDetailManager dmgr = new DefectDetailManager();
		DefectDetail dd = dmgr.getDefectDetail(defect_id);	
 
 	
		//ClosedData Null check(if null -> "")
	    String cl_date = "";
	   	if ( dd.getClosedDate() == null) {
	   	 	cl_date = "";
	   	}else{
	   	 	cl_date = dd.getClosedDate().toString();
	   	} 	
			
			
		//if user is administrator(level : 1) can assign defects to person(level : 1)
		//  and change defect status(check with AccessLevelID)
		//if user is General user(level : 2) or read Only(level : 3) or QA(level : 4) can only update  the detail
		//useing "disabled" option of "selection" tag 
		String defect_status_check = ""; //for "selection" tag of defect_status 
		String assignee_id_check = "";
		
		int current_user_userid = 3; //session.getAttribute(userid); ///usering session.userid
		
		//retreive current user_accessLevelID
		DefectDetailManager dmgr2 = new DefectDetailManager();
		int current_user_accessLevelID = dmgr2.getUserAccessLevelID(current_user_userid);
		
		//if check current_user_level 1 can assigne, otherwise disable the selection tag 
		if (current_user_accessLevelID != 1 ) {
				defect_status_check = "defect_status_dis\" disabled=\"disabled\"";
				assignee_id_check = "assignee_id_dis\" disabled=\"disabled\"";
				out.println("<input type=\"hidden\" name=\"defect_status\" value=\"" + dd.getStatusID() + "\">");
				out.println("<input type=\"hidden\" name=\"assignee_id\" value=\"" + dd.getAssignedTo() + "\">");
		}else{
			    defect_status_check = "defect_status";
			    assignee_id_check = "assignee_id";
		}//if (current_user_accessLevelID != 1 )
			
%>	

		<table class="pure-table" width="700">
		    <thead>
		    	<tr class="pure-table-odd" >
			   		<th align="center">Summary</th>
			       	<th align="center" width="80%"><%=dd.getSummary()%> </th>
		   		</tr>
		    </thead>
		    <tbody>
			    <tr>
			        <td height="150" align="center">Description</td>
			        <td height="150" align="left" >
			       		 <input type="hidden" name="defect_id" value="<%=dd.getDefectID()%>">
			       		 <input type="hidden" name="summary" value="<%=dd.getSummary()%>">
			       		 <input type="hidden" name="email_add" value="<%=dd.getEmailAdd()%>">
			        	<textarea name="defect_details_update" rows="10" cols="70" ><%=dd.getDetails()%></textarea>			        	
			        </td>
			    </tr>
			   
			    <tr class="pure-table-odd">
    				<td align="center">Register date</td>
        			<td align="center"><%=dd.getDetectedOn().toString() %></td>
    			</tr> 
				<tr >
    				<td align="center">Register</td>
       				<td align="center"><%=dd.getDetectedByFname()%> <%=dd.getDetectedByLname()%></td>
    			</tr>    
				<tr class="pure-table-odd">
    				<td align="center">Status</td>
        			<td align="center">
        				<select class="pure-input-1-4" name="<%=defect_status_check%>" >
  <%
   			 
		//Declear DefectDetail 		
  		DefectDetailManager smgr = new DefectDetailManager();
  		List<DefectStatus> defectstatusList = new ArrayList<DefectStatus>();
  		defectstatusList = smgr.getDefectStatusInfo();
		
		int de_status_id = 1;
		String de_status_descrip = "None";
		
		//retrieve defect status list 		
		for(int i=0; i< defectstatusList.size() ; i++ ) {
 
				if ( defectstatusList.get(i).getStatusID() == dd.getStatusID()){
					    out.println("<option value=\"" + defectstatusList.get(i).getStatusID()+ "\" selected=\"selected\">" + defectstatusList.get(i).getDescription() + "</option>");
				}else{
						out.println("<option value=\"" + defectstatusList.get(i).getStatusID()+ "\">" + defectstatusList.get(i).getDescription() + "</option>");
				}
		}//for(int i=0; i< defectstatusList.size() ; i++ )
		    
  %>      			
        		
        				</select>
                    </td>                
    			</tr>     
    			<tr > 
					<td align="center">Assignee</td>
        			<td align="center">
        				<select class="pure-input-1-4" name="<%=assignee_id_check%>" >
 <%	       	

		//retrieve userid and username from user table with AccessLevelID=1 to list up assignee
		//Declear DefectDetailManager 		
  		DefectDetailManager amgr = new DefectDetailManager();
  		List<User> adminList = new ArrayList<User>();
  		adminList = amgr.getAdministratorInfo();
  		
  		
  		for(int j=0 ; j <adminList.size();j++ ){
			    //"dd.getAssigneeID=0" means not yet assigned  
				if ( dd.getAssignedTo() != 0 && dd.getAssignedTo() == adminList.get(j).getUserID()  ){
					    out.println("<option value=" + adminList.get(j).getUserID()+ " selected=\"selected\">" + adminList.get(j).getFName() + ","+ adminList.get(j).getLName() + "</option>");
				}else if(dd.getAssignedTo() == 0 && j == 0){ 
					    //if assigneeid == 0 means "unselected" yet,
					   out.println("<option value=0 selected=\"selected\">" + "Select assignee" + "</option>");
					   out.println("<option value=\"" + adminList.get(j).getUserID()+ "\">" + adminList.get(j).getFName() + ","+ adminList.get(j).getLName() + "</option>");
				}else{
						out.println("<option value=\"" + adminList.get(j).getUserID()+ "\">" + adminList.get(j).getFName() + ","+ adminList.get(j).getLName() + "</option>");
				}
 
  		}//for(int j=0 ; j <adminList.size();j++ )
%>        		
						</select>	
        			</td>        
    			</tr>  
    			<tr class="pure-table-odd">
    				<td align="center">Closed data</td>
        			<td align="center"><%=cl_date%></td>
				</tr>
    		</tbody>
		</table>
			
						


<!------------------------------------------------->
<!------------------- link to list/edit/submit pages----------------------->
<!------------------------------------------------->
</br></br></br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a class="pure-button pure-button-primary" href="./list.jsp">All list</a>&nbsp;&nbsp;
<button type="submit" class="pure-button pure-button-primary">Submit</button>

</br>
</br>
</br>

</center>
</body>
</html>